<template>
	<view class="content">
		<view class="h-title"></view>

		<view class="input-group">
			<view class="input-row border">
				<text class="title">用户名：</text>
				<input type="text" v-model="name" placeholder="请输入用户名" />
			</view>
			<view class="input-row">
				<text class="title">密码：</text>
				<input type="text" password="true" v-model="password" placeholder="请输入密码" />
			</view>
		</view>
		<view class="btn-row"><button type="primary" class="primary" @tap="bindLogin">登录</button></view>
		<view class="action-row"><navigator url="../setting/setting">设置</navigator></view>
		<view class="text_explain" @tap="tap_obj">《使用说明及隐私条款》</view>
		
	</view>
</template>

<script>
import net from '../../net.js';
import service from '../../service.js';
import { mapState, mapMutations } from 'vuex';

export default {
	data() {
		return {
			name: '',
			password: ''
		};
	},
	computed: mapState(['forcedLogin']),
	onLoad() {
		let user = service.getUserName();
		this.name = user.username;
		this.password = user.password;
	},
	methods: {
		bindLogin() {
			if (this.name.length == '') {
				uni.showToast({ icon: 'none', title: '用户名不能为空' });
				return;
			}

			if (this.password.length == 0) {
				uni.showToast({ icon: 'none', title: '密码不能为空' });
				return;
			}

			if (this.password.length < 6) {
				uni.showToast({ icon: 'none', title: '密码最短为 6 位' });
				return;
			}

			const data = {
				username: this.name,
				password: this.password
			};

			net.netPost(
				'/module/api/main/login',
				data,
				(res, msg) => {
					if (res) {
						console.log(res);
						res.userinfo.username = this.name;
						res.userinfo.password = this.password;
						service.setUserName(data);
						service.addUser(res.userinfo);
						setTimeout(() => {
							uni.reLaunch({
								url: '../main/main'
							});
						}, 0);
					}
				},
				null,
				null,
				true
			);
		},

		tap_obj() {
			// #ifdef  APP-PLUS  || MP-WEIXIN
			plus.runtime.openWeb('http://116.62.193.56:8092/uploads/phone/declare.html');
			// #endif
			//#ifdef H5
			self.location.href = 'http://116.62.193.56:8092/uploads/phone/declare.html';
			//#endif
		}
	}
};
</script>

<style>
.h-title {
	text-align: center;
	font-size: 45upx;
	margin-bottom: 10upx;
	font-weight: bold;
}

.action-row {
	display: flex;
	flex-direction: row;
	justify-content: center;
}

.input-row .title {
	width: 30%;
}

.action-row navigator {
	color: #007aff;
	padding: 0 20upx;
}
.text_explain {
	color: #0faeff;
	text-align: center;
	margin-top: 50upx;
}
</style>
